﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.FxCop;
using Microsoft.FxCop.Sdk;

namespace CustomCodeAnalysisRules
{
    public class AvoidExposingPublicConstants : BasicStaticAnalysisRule
    {
        public AvoidExposingPublicConstants()
            : base("AvoidExposingPublicConstants")
        { }

        public override Microsoft.FxCop.Sdk.ProblemCollection Check(Microsoft.FxCop.Sdk.Member member)
        {
            Field f = member as Field;
            if (f == null)
            {
                return null;
            }

            if (member.DeclaringType is Microsoft.FxCop.Sdk.EnumNode)
            {
                return null;
            }

            if (member.IsVisibleOutsideAssembly && f.IsLiteral)
            {
                Problems.Add(new Problem(GetResolution(member.Name.Name)));
            }

            return Problems;
        }

        public override TargetVisibilities TargetVisibility
        {
            get
            {
                return TargetVisibilities.ExternallyVisible;
            }
        }

    }
}
